package com.shundr.common.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.shundr.R;
import com.shundr.common.model.InviteInfo;
import com.shundr.common.util.DateUtil;
import com.shundr.frame.util.StringUtil;

/**
 * 
 * ContactAdapter 联系人数据适配器
 * 
 * @author larry 2015-4-13 下午4:26:47 
 * @version 1.0.0
 *
 */
public class InvitedAdapter extends BaseAdapter{
	public List<InviteInfo> mList;
	private Context mContext;

	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int index) {
		return mList.get(index);
	}

	@Override
	public long getItemId(int id) {
		return id;
	}

	public InvitedAdapter(List<InviteInfo> list, Context mContext) {
		super();
		this.mList = list;
		this.mContext = mContext;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup viewGroup) {
		ViewHold viewHold = null;
		if(convertView == null){
			convertView = LayoutInflater.from(mContext).inflate(R.layout.item_contact_list,null);
			viewHold = new ViewHold();
			viewHold.btnInvitation = (Button) convertView.findViewById(R.id.btn_invitation);
			viewHold.tvName = (TextView) convertView.findViewById(R.id.tv_name);
			viewHold.tvPhone = (TextView) convertView.findViewById(R.id.tv_phone);
			convertView.setTag(viewHold);
		}else{
			viewHold = (ViewHold) convertView.getTag();
		}
		try {
			final InviteInfo info = mList.get(position);
			viewHold.btnInvitation.setVisibility(View.GONE);
			if(StringUtil.isNull(info.getInviteContactName())){
				viewHold.tvName.setText(info.getInvitePhone());
			}else{
				viewHold.tvName.setText(info.getInviteContactName() + " " + info.getInvitePhone());
			}
			viewHold.tvPhone.setText(DateUtil.getInterval(info.getInsertTime()));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return convertView;
	}
	
	static class ViewHold{
		Button btnInvitation;
		TextView tvName;
		TextView tvPhone;
	}
}
